/**
 * Created with IntelliJ IDEA.
 * User: chenkaiyu
 * Date: 15-4-25
 * Time: 上午10:42
 * To change this template use File | Settings | File Templates.
 */

var boom = function(){
    function showBlockUI(message) {
        Metronic.blockUI({
            boxed: true,
            message: message
        });
        window.setTimeout(function () {
            Metronic.unblockUI();
        }, 500);
    };

    return{
        init:function(){

            $("#hgi").blur(function(){
                var $obj = $("#hgi");
                var hgi = $obj.val();
                validate.init($obj);

                if(hgi!="")   {
                    if(validate.isNotNumber(hgi)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    var boom = {
                        "hgi":$("#hgi").val()
                    };
                    $.ajax({
                        url: basePath + "quality/boom/saveTheValueOfHGIAndKvtI",
                        contentType:"application/json; charset=utf-8",
                        data:JSON.stringify(boom),
                        dataType:"json",
                        type:"post",
                        success: function (data) {
                            $("#kvti").val(data.returnMsg);
                            $("#kvti_show").html(data.returnMsg);
                        }
                    })
                }else{
                    validate.invalid();
                    return;
                }

            })

            $("#ke").blur(function(){
                var $obj = $("#ke");
                var ke = $obj.val();
                validate.init($obj);
                if(ke!="")   {
                    if(validate.isNotNumber(ke)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    var grey = {
                        "ke":$("#ke").val()
                    };
                    $.ajax({
                        url: basePath + "quality/boom/saveTheValueOfKe",
                        contentType:"application/json; charset=utf-8",
                        data:JSON.stringify(grey),
                        dataType:"json",
                        type:"post"
                    })
                }else{
                    validate.invalid();
                    return;
                }

            })

            $("#ai").blur(function(){
                var $obj = $("#ai");
                var ai = $obj.val();
                validate.init($obj);
                if(ai!="")   {
                    if(validate.isNotNumber(ai)){
                        validate.invalid();
                        return;
                    }
                    validate.valid();
                    var grey = {
                        "ai":$("#ai").val()
                    };
                    $.ajax({
                        url: basePath + "quality/boom/saveTheValueOfAi",
                        contentType:"application/json; charset=utf-8",
                        data:JSON.stringify(grey),
                        dataType:"json",
                        type:"post"
                    })
                }else{
                    validate.invalid();
                    return;
                }
            })

            $("#calculation_E22").click(function () {
                var boom = {
                    "hgi": $("#hgi").val()
                }
                showBlockUI("计算中..");
                $.ajax({
                    url: basePath + "quality/boom/calculationE22",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(boom),
                    dataType:"json",
                    type: "post",
                    success: function (data) {
                        $("#kvti").val(data.returnMsg);
                        var result = "<li><span>"+ "VTI可磨性系数------->" +" </span><span>"+ data.returnMsg + "</span></li>";
                        $("#result").append(result);
                    }
                })
            })

            $("#calculation_E50").click(function () {
                var boom = {
                }
                showBlockUI("计算中..");
                $.ajax({
                    url: basePath + "quality/boom/calculationE50",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(boom),
                    dataType:"json",
                    type: "post",
                    success: function (data) {
                        $("#kgc").val(data.returnMsg);
                        $("#kgc_show").html(data.returnMsg);
                    }
                })
            })

            $("#calculation_E51").click(function () {
                var boom = {
                }
                showBlockUI("计算中..");
                $.ajax({
                    url: basePath + "quality/boom/calculationE51",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(boom),
                    dataType:"json",
                    type: "post",
                    success: function (data) {
                        $("#hm").val(data.returnMsg);
                        $("#hm_show").html(data.returnMsg);
                    }
                })
            })

            $("#calculation_E80").click(function () {
                var boom = {
                }
                showBlockUI("计算中..");
                $.ajax({
                    url: basePath + "quality/boom/calculationE80",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(boom),
                    dataType:"json",
                    type: "post",
                    success: function (data) {
                        $("#kd").val(data.returnMsg);
                        $("#kd_show").html(data.returnMsg);
                    }
                })
            })

            $("#save").click(function(){
                window.location.href = basePath + "quality/boom/save";
            })

        },

        recover:function(){
            $.get(basePath + "quality/boom/recover",function(data){
                $("#hgi").val(getValidRecoverVal(data.hgi));
                $("#kvti").val(getValidRecoverVal(data.kvti));
                $("#ke").val(getValidRecoverVal(data.ke));
                $("#kgc").val(getValidRecoverVal(data.kgc));
                $("#ai").val(getValidRecoverVal(data.ai));
                $("#hm").val(getValidRecoverVal(data.hm));
                $("#kd").val(getValidRecoverVal(data.kd));

                $("#kvti_show").html(getValidRecoverVal(data.kvti));
                $("#kgc_show").html(getValidRecoverVal(data.kgc));
                $("#hm_show").html(getValidRecoverVal(data.hm));
                $("#kd_show").html(getValidRecoverVal(data.kd));
            });
        }
    }
}()
